﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GeoFly
{
    public partial class RunParaDialog : Form
    {
        public RunParaDialog()
        {
            InitializeComponent();
        }

        private void RunParaDialog_Load(object sender, EventArgs e)
        {

            //潜在蒸散发
            PET_METHOD petmethod = HydroSimulate.g_ModelRunPara.PETMethod;
            if (petmethod == PET_METHOD.PET_PENMAN_MONTEITH)
                this.comboBox_PET.SelectedIndex = 0;
            else if (petmethod == PET_METHOD.PET_PRISTLEY_TAYLOR)
                this.comboBox_PET.SelectedIndex = 1;
            else if (petmethod == PET_METHOD.PET_HARGREAVES)
                this.comboBox_PET.SelectedIndex = 2;
            else if (petmethod == PET_METHOD.PET_REAL)
                this.comboBox_PET.SelectedIndex = 3;
                
            //实际蒸散发
            AET_METHOD aetmethod = HydroSimulate.g_ModelRunPara.AETMethod;
            if (aetmethod == AET_METHOD.AET_BY_CROP_COEFFICIENTS)
                this.comboBox_AET.SelectedIndex = 0;
            else if (aetmethod == AET_METHOD.AET_BY_COMPRELATIONSHIP)
                this.comboBox_AET.SelectedIndex = 1;
            else if (aetmethod == AET_METHOD.AET_BY_COMPRELA_AND_KOJIMA)
                this.comboBox_AET.SelectedIndex = 2;
                
            //插值方法
            SpatialInterMethod interpmethod = HydroSimulate.g_ModelRunPara.InterpMethod;
            if (interpmethod == SpatialInterMethod.SPATIAL_IDW_METHOD)
                this.comboBox_Inter.SelectedIndex = 0;
            else if (interpmethod == SpatialInterMethod.SPATIAL_NEARIST_METHOD)
                this.comboBox_Inter.SelectedIndex = 1;
            else if (interpmethod == SpatialInterMethod.SPATIAL_THIESSEN_METHOD)
                this.comboBox_Inter.SelectedIndex = 2;
            else if (interpmethod == SpatialInterMethod.SPATIAL_PRISM_METHOD)
                this.comboBox_Inter.SelectedIndex = 3;
            else if (interpmethod == SpatialInterMethod.SPATIAL_GIDW_METHOD)
                this.comboBox_Inter.SelectedIndex = 4;
            //LAI计算方法
            DailyLAICalMethod laimethod=HydroSimulate.g_ModelRunPara.DLAICalcMethod;

            if (laimethod == DailyLAICalMethod.DAILY_LAI_CAL_SINE)
                this.comboBoxLAI.SelectedIndex = 0;
            else if (laimethod == DailyLAICalMethod.DAILY_LAI_CAL_LINEAR)
                this.comboBoxLAI.SelectedIndex = 1;
            else if (laimethod == DailyLAICalMethod.DAILY_LAI_BY_MONTH)
                this.comboBoxLAI.SelectedIndex = 2;
            //干旱指数计算方法
            if (HydroSimulate.g_ModelRunPara.AIMethod == AridIndexMethod.Surface_Soil_Moisture)
                this.comboBox_AridIndex.SelectedIndex = 0;
            else if (HydroSimulate.g_ModelRunPara.AIMethod == AridIndexMethod.Veg_WaterDeficit_Index)
                this.comboBox_AridIndex.SelectedIndex = 1;
                
            //降水-径流过程类型
            if (HydroSimulate.g_ModelRunPara.RunoffSimuType == RunOffSimuType.STORM_RUNOFF_SIMULATION)
                this.comboBox_RunType.SelectedIndex = 0;
            else if (HydroSimulate.g_ModelRunPara.RunoffSimuType == RunOffSimuType.LONGTERM_RUNOFF_SIMULATION)
                this.comboBox_RunType.SelectedIndex = 1;
            //下渗曲线类型
            if (HydroSimulate.g_ModelRunPara.InfilCurveType == InfilltrationType.INFILTRATION_HORTON)
                this.comboBox_InfType.SelectedIndex = 0;
            else if (HydroSimulate.g_ModelRunPara.InfilCurveType == InfilltrationType.INFILTRATION_GREEN_AMPT)
                this.comboBox_InfType.SelectedIndex = 1;
            //坡面汇流方法
            if (HydroSimulate.g_ModelRunPara.SurfRouteMethod == SurfRouteMehtod.ROUTE_MUSK_CONGE)
                this.comboBox_SurfRoute.SelectedIndex =0;
            else if (HydroSimulate.g_ModelRunPara.SurfRouteMethod == SurfRouteMehtod.ROUTE_PURE_LAG)
                this.comboBox_SurfRoute.SelectedIndex = 1;
                
            //壤中流汇流方法
            if (HydroSimulate.g_ModelRunPara.LatRouteMethod == SurfRouteMehtod.ROUTE_MUSK_CONGE)
                this.comboBox_LatRoute.SelectedIndex = 0;
            else if (HydroSimulate.g_ModelRunPara.LatRouteMethod == SurfRouteMehtod.ROUTE_PURE_LAG)
                this.comboBox_LatRoute.SelectedIndex = 1;
                
            //地下径流汇流方法
            if (HydroSimulate.g_ModelRunPara.BaseRouteMethod == SurfRouteMehtod.ROUTE_MUSK_CONGE)
                this.comboBox_BaseRoute.SelectedIndex = 0;
            else if (HydroSimulate.g_ModelRunPara.BaseRouteMethod == SurfRouteMehtod.ROUTE_PURE_LAG)
                this.comboBox_BaseRoute.SelectedIndex = 1;
            //河道汇流方法
            if (HydroSimulate.g_ModelRunPara.RiverRouteMethod == RiverRouteMethod.ROUTE_MUSK_CONGE)
                this.comboBox_ChannelRoute.SelectedIndex = 0;
            else if (HydroSimulate.g_ModelRunPara.RiverRouteMethod == RiverRouteMethod.ROUTE_PURE_LAG)
                this.comboBox_ChannelRoute.SelectedIndex = 1;
            else if (HydroSimulate.g_ModelRunPara.RiverRouteMethod == RiverRouteMethod.ROUTE_MUSKINGUM_COMBINE_FIRST)
                this.comboBox_ChannelRoute.SelectedIndex = 2;
            else if (HydroSimulate.g_ModelRunPara.RiverRouteMethod == RiverRouteMethod.ROUTE_MUSKINGUM_ROUTE_FIRST)
                this.comboBox_ChannelRoute.SelectedIndex = 3;
                
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("原有参数将被替换", "?", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                return;
            //潜在蒸散发
            if(this.comboBox_PET.SelectedIndex==0)
                HydroSimulate.g_ModelRunPara.PETMethod=PET_METHOD.PET_PENMAN_MONTEITH;
            else if(this.comboBox_PET.SelectedIndex==1)
                HydroSimulate.g_ModelRunPara.PETMethod=PET_METHOD.PET_PRISTLEY_TAYLOR;
            else if(this.comboBox_PET.SelectedIndex==2)
                HydroSimulate.g_ModelRunPara.PETMethod=PET_METHOD.PET_HARGREAVES;
            else if(this.comboBox_PET.SelectedIndex==3)
                HydroSimulate.g_ModelRunPara.PETMethod=PET_METHOD.PET_REAL;
            //实际蒸散发
            if (this.comboBox_AET.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.AETMethod = AET_METHOD.AET_BY_CROP_COEFFICIENTS;
            else if (this.comboBox_AET.SelectedIndex == 1)
                HydroSimulate.g_ModelRunPara.AETMethod = AET_METHOD.AET_BY_COMPRELATIONSHIP;
            else if (this.comboBox_AET.SelectedIndex == 2)
                HydroSimulate.g_ModelRunPara.AETMethod = AET_METHOD.AET_BY_COMPRELA_AND_KOJIMA;
            //插值方法
            if (this.comboBox_Inter.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.InterpMethod = SpatialInterMethod.SPATIAL_IDW_METHOD;
            else if (this.comboBox_Inter.SelectedIndex == 1)
                HydroSimulate.g_ModelRunPara.InterpMethod = SpatialInterMethod.SPATIAL_NEARIST_METHOD;
            else if (this.comboBox_Inter.SelectedIndex == 2)
                HydroSimulate.g_ModelRunPara.InterpMethod = SpatialInterMethod.SPATIAL_THIESSEN_METHOD;
            else if (this.comboBox_Inter.SelectedIndex == 3)
                HydroSimulate.g_ModelRunPara.InterpMethod = SpatialInterMethod.SPATIAL_PRISM_METHOD;
            else if (this.comboBox_Inter.SelectedIndex == 4)
                HydroSimulate.g_ModelRunPara.InterpMethod = SpatialInterMethod.SPATIAL_GIDW_METHOD;
            //LAI计算方法
            if (this.comboBoxLAI.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.DLAICalcMethod = DailyLAICalMethod.DAILY_LAI_CAL_SINE;
            else if (this.comboBoxLAI.SelectedIndex == 1)
                HydroSimulate.g_ModelRunPara.DLAICalcMethod = DailyLAICalMethod.DAILY_LAI_CAL_LINEAR;
            else if (this.comboBoxLAI.SelectedIndex == 2)
                HydroSimulate.g_ModelRunPara.DLAICalcMethod = DailyLAICalMethod.DAILY_LAI_BY_MONTH;
            //干旱指数计算方法
            if (this.comboBox_AridIndex.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.AIMethod = AridIndexMethod.Surface_Soil_Moisture;
            else if (this.comboBox_AridIndex.SelectedIndex == 1)
                HydroSimulate.g_ModelRunPara.AIMethod = AridIndexMethod.Veg_WaterDeficit_Index;
            //降水-径流过程类型
            if (this.comboBox_RunType.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.RunoffSimuType = RunOffSimuType.STORM_RUNOFF_SIMULATION;
            else
                HydroSimulate.g_ModelRunPara.RunoffSimuType = RunOffSimuType.LONGTERM_RUNOFF_SIMULATION;
            //下渗曲线类型
            if (this.comboBox_InfType.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.InfilCurveType = InfilltrationType.INFILTRATION_HORTON;
            else
                HydroSimulate.g_ModelRunPara.InfilCurveType = InfilltrationType.INFILTRATION_GREEN_AMPT;
            //坡面汇流方法
            if (this.comboBox_SurfRoute.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.SurfRouteMethod = SurfRouteMehtod.ROUTE_MUSK_CONGE;
            else if (this.comboBox_SurfRoute.SelectedIndex == 1)
                HydroSimulate.g_ModelRunPara.SurfRouteMethod = SurfRouteMehtod.ROUTE_PURE_LAG;
            //壤中流汇流方法
            if (this.comboBox_LatRoute.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.LatRouteMethod = SurfRouteMehtod.ROUTE_MUSK_CONGE;
            else if (this.comboBox_LatRoute.SelectedIndex == 1)
                HydroSimulate.g_ModelRunPara.LatRouteMethod = SurfRouteMehtod.ROUTE_PURE_LAG;
            //地下径流汇流方法
            if (this.comboBox_BaseRoute.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.BaseRouteMethod = SurfRouteMehtod.ROUTE_MUSK_CONGE;
            else if (this.comboBox_BaseRoute.SelectedIndex == 1)
                HydroSimulate.g_ModelRunPara.BaseRouteMethod = SurfRouteMehtod.ROUTE_PURE_LAG;
            //河道汇流方法
            if (this.comboBox_ChannelRoute.SelectedIndex == 0)
                HydroSimulate.g_ModelRunPara.RiverRouteMethod =RiverRouteMethod.ROUTE_MUSK_CONGE;
            else if (this.comboBox_ChannelRoute.SelectedIndex == 1)
                HydroSimulate.g_ModelRunPara.RiverRouteMethod =RiverRouteMethod.ROUTE_PURE_LAG;
            else if (this.comboBox_ChannelRoute.SelectedIndex == 2)
                HydroSimulate.g_ModelRunPara.RiverRouteMethod =RiverRouteMethod.ROUTE_MUSKINGUM_COMBINE_FIRST;
            else
                HydroSimulate.g_ModelRunPara.RiverRouteMethod =RiverRouteMethod.ROUTE_MUSKINGUM_ROUTE_FIRST;

            HydroSimulate.g_ModelRunPara.WritePara(HydroSimulate.path+"\\SysPara\\RunPara.txt");
        }
    }
}
